﻿
Partial Class admin_city_manager
    Inherits Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        If Request("delid") <> "" Then

            Dim id As Guid

            id = Guid.Parse(Request("delid"))

            Dim _context As New TaxiEntities

            Dim city As cities

            city = _context.cities.FirstOrDefault(Function(x) x.city_id = id)

            _context.cities.Remove(city)

            _context.SaveChanges()

            Response.Redirect("/admin/city_manager.aspx")

        End If

        If Request("name") <> "" Then

            If (Request("loc") <> "") Then

                Dim id As Guid

                Dim _context As New TaxiEntities

                Dim city As cities

                If (Request("id") <> "") Then

                    id = Guid.Parse(Request("id"))

                    city = _context.cities.FirstOrDefault(Function(x) x.city_id = id)

                Else

                    id = Guid.NewGuid

                    city = New cities

                End If

                city.city_id = id

                city.city_name = Request("name")

                city.city_position = Request("loc").Replace("(", "").Replace(")", "")

                If (Request("id") = "") Then

                    _context.cities.Add(city)

                End If

                _context.SaveChanges()
                Response.Redirect("/admin/city_manager.aspx")
            End If


        End If

    End Sub

End Class
